import React from 'react';
import {putLsCarAccreditInsertCarAccredit} from '../../../../../api'
import { Modal, Form, DatePicker, message } from "antd";
import moment from 'moment';
const { RangePicker } = DatePicker;

/**
 * @description: 车辆临时进出时间记录
 * @author: xiaoxujs
 * @updata: xiaoxujs（2021-09-10）创建
 */

const AddTemporaryModule = ({ setAddTemporaryModuleShow, addTemporaryModuleShow, carId, listFun }) => {
    const [form] = Form.useForm();
    const {validateFields, resetFields} = form;
    const handleOk = () => {
        validateFields().then(values => {
            const parames = {
                carId,
                effectiveStartIn: moment(values.enterTime[0]).format("YYYY-MM-DD HH:mm:ss"),
                effectiveEndIn: moment(values.enterTime[1]).format("YYYY-MM-DD HH:mm:ss"),
                effectiveStartOut: moment(values.nextTime[0]).format("YYYY-MM-DD HH:mm:ss"),
                effectiveEndOut: moment(values.nextTime[1]).format("YYYY-MM-DD HH:mm:ss"),
            }
            ;(async () => {
                const {code, msg} = await putLsCarAccreditInsertCarAccredit(parames);
                if(code === '20000') {
                    message.success('添加成功！');
                    resetFields();
                    listFun();
                    setAddTemporaryModuleShow(false);
                }else{  
                    message.error(msg);
                }
            })()
        })
    };

    const handleCancel = () => {
        resetFields();
        setAddTemporaryModuleShow(false);
    };
    return (
        <Modal title="添加临时进出时间" visible={addTemporaryModuleShow} onOk={handleOk} onCancel={handleCancel}>
            <Form
                labelCol={{ span: 4 }}
                wrapperCol={{ span: 20 }}
                form = {form}
            >
                <Form.Item
                    label="驶入时间"
                    name="enterTime"
                    rules={[{ required: true, message: '请输入驶入时间!' }]}
                >
                    <RangePicker renderExtraFooter={() => 'extra footer'} showTime />
                </Form.Item>
                <Form.Item
                    label="驶出时间"
                    name="nextTime"
                    rules={[{ required: true, message: '请输入驶出时间!' }]}
                >
                    <RangePicker renderExtraFooter={() => 'extra footer'} showTime />
                </Form.Item>
            </Form>
        </Modal>
    )
}

export default AddTemporaryModule;